package com.zy.struts.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.zy.struts.dao.DAOFactory;
import com.zy.struts.dao.UserDAO;
import com.zy.struts.domain.User;

public class LoginAction extends ActionSupport implements ModelDriven<User> {

	private User user = new User();

	public User getModel() {

		return user;
	}

	public String login() {
		UserDAO uDao = (UserDAO) DAOFactory.getInstance().getDAO("UserDAO");
		User loginUser = uDao.login(user.getName(), user.getPassword());
		
	 
		if (null!=loginUser){
			Map session=ActionContext.getContext().getSession();
			session.put("user", loginUser);
			return SUCCESS;
		}
		return "login";
	}

}
